#!/usr/bin/env python
# coding: utf-8

from typing import List

class Solution(object):
    @staticmethod
    def solution(nums: List[int]) -> int:
        # your code here
        l = len(nums)
        if l < 2:
            return 0
        i = 0
        j = l - 1
        max_area: int = 0
        while i < j:
            if nums[i] <= nums[j]:
                area = nums[i] * (j - i)
                if max_area < area:
                    max_area = area
                i += 1
            else:
                area = nums[j] * (j - i)
                if max_area < area:
                    max_area = area
                j -= 1
        return max_area

    @staticmethod
    def test():
        # test code
        ts = [
            [1,8,6,2,5,4,8,3,7],
            [],
            [1],
            [4,3],
        ]
        want = [49,0,0,3]
        i = 0
        while i < len(ts):
            got = Solution.solution(ts[i])
            assert got == want[i], "i: %s got: %s want: %s" % (i, got, want[i])
            i += 1

        print("Test Done!")

if __name__ == "__main__":
    Solution.test()

